package com.easyaccount.controller;

import com.easyaccount.commons.CommonResp;
import com.easyaccount.commons.TablePage;
import com.easyaccount.model.Menu;
import com.easyaccount.service.DeptService;
import com.easyaccount.service.MenuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    @RequestMapping("all")
    public CommonResp all(){
        return menuService.list();
    }

    @RequestMapping("list")
    public TablePage list(TablePage tablePage){
        return menuService.searchByName(tablePage, null);
    }

    @RequestMapping("add")
    public CommonResp list(Menu menu){
        return menuService.save(menu);
    }

    @RequestMapping("update")
    public CommonResp update(Menu menu){
        return menuService.update(menu);
    }

    @RequestMapping("delete")
    public CommonResp delete(Menu menu){
        return menuService.delete(menu);
    }

    @RequestMapping("search")
    public TablePage search(TablePage tablePage,@RequestParam("menuName") String menuName){
        TablePage result = menuService.searchByName(tablePage, menuName);
        return result;
    }

}
